home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / xv / xvmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  4.2 KB  |  158 lines

  1. /* Pulldown menu code.
  2.    Copyright (C) 1995 Jakub Jelinek.
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19. #include <xview/xview.h>
  20. #include <xview/frame.h>
  21. #include <xview/panel.h>
  22.  
  23. #include <string.h>
  24. #include <malloc.h>
  25. #include "mad.h"
  26. #include "util.h"
  27. #include "menu.h"
  28. #include "dialog.h"
  29. #include "xvmain.h"
  30.  
  31. extern Frame mcframe;
  32. extern Frame menubarframe;
  33. int menubar_visible = 1; /* We do not use this */
  34. extern int is_right;
  35. extern Dlg_head *midnight_dlg;
  36.  
  37. static void menu_notify_proc (Menu menu, Menu_item menu_item)
  38. {
  39.     void (*callback)(void *) = (void (*)(void *)) xv_get (menu_item, 
  40.         MENU_CLIENT_DATA);
  41.         
  42. /*    is_right = strcmp ((char *) xv_get (menu, XV_KEY_DATA, MENU_CLIENT_DATA),
  43.         "Left");*/
  44.     
  45.     xv_post_proc (midnight_dlg, callback, NULL);
  46. }
  47.  
  48. Menu create_menu (char *name, menu_entry *entries, int count)
  49. {
  50.     Menu menu;
  51.     int i;
  52.  
  53.     menu = (Menu) xv_create ((Frame)NULL, MENU,
  54.         MENU_CLIENT_DATA, name,
  55.         NULL);
  56.     for (i = 0; i < count; i++)
  57.         if (*(entries [i].text))
  58.             xv_set (menu, 
  59.                 MENU_ITEM,
  60.                     MENU_STRING, entries [i].text,
  61.                     MENU_NOTIFY_PROC, menu_notify_proc,
  62.                     MENU_CLIENT_DATA, entries [i].call_back,
  63.                     NULL,
  64.                 NULL);
  65.         else
  66.             xv_set (menu,
  67.                 MENU_ITEM,
  68.                     MENU_STRING, "",
  69.                     MENU_FEEDBACK, FALSE,
  70.                     NULL,
  71.                 NULL);
  72.     return menu;
  73. }
  74.  
  75. void destroy_menu (Menu menu)
  76. {
  77. }
  78.  
  79. int quit_cmd (void);
  80.  
  81. void menu_done_proc (Frame frame)
  82. {
  83.     xv_post_proc (midnight_dlg, (void (*)(void *))quit_cmd, NULL);
  84. }
  85.  
  86. int create_menubar (WMenu *menubar)
  87. {
  88.     int i;
  89.  
  90.     Panel menubarpanel;
  91.  
  92.     menubarframe = (Frame) xv_create (mcframe, FRAME,
  93.         XV_X, 10,
  94.         XV_Y, 10,
  95.         XV_WIDTH, 10000,
  96.         XV_HEIGHT, 300,
  97.         FRAME_LABEL, "The Midnight X Commander",
  98.         FRAME_SHOW_FOOTER, FALSE,
  99.         FRAME_DONE_PROC, menu_done_proc,
  100.         NULL);
  101.         
  102.     menubarpanel = (Panel) xv_create (menubarframe, PANEL, 
  103.         PANEL_LAYOUT, PANEL_HORIZONTAL,
  104.         NULL);
  105.     
  106.     for (i = 0; i < menubar->items; i++)
  107.         xv_create (menubarpanel, PANEL_BUTTON,
  108.             PANEL_LABEL_STRING, 
  109.                 xv_get (menubar->menu [i], 
  110.                     MENU_CLIENT_DATA,
  111.                     NULL),
  112.             PANEL_ITEM_MENU, menubar->menu [i],
  113.             NULL);
  114.     window_fit (menubarpanel);
  115.     window_fit (menubarframe);
  116.     xv_set (menubarframe, 
  117.         XV_SHOW, TRUE, 
  118.         NULL);
  119.     menubar->widget.wdata = (widget_data) menubarframe;
  120.     return 1;
  121. }
  122.  
  123. static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par)
  124. {
  125.     switch (msg) {
  126.         case WIDGET_INIT: return create_menubar (menubar);
  127.     }
  128.     return default_proc (h, msg, par);
  129. }
  130.  
  131. static int menubar_event (Gpm_Event *event, WMenu *menubar)
  132. {
  133.     return MOU_NORMAL;
  134. }
  135.  
  136. static void menubar_destroy (WMenu *menubar)
  137. {
  138.     xv_destroy_safe ((Frame)(menubar->widget.wdata));
  139. }
  140.  
  141. WMenu *menubar_new (int y, int x, int cols, Menu menu [], int items)
  142. {
  143.     WMenu *menubar = (WMenu *) xmalloc (sizeof (WMenu), "menubar_new");
  144.  
  145.     init_widget (&menubar->widget, y, x, 1, cols,
  146.                  (callback_fn) menubar_callback,
  147.          (destroy_fn)  menubar_destroy,
  148.          (mouse_h)     menubar_event);
  149.     menubar->menu = menu;
  150.     menubar->active = 0;
  151.     menubar->dropped = 0;
  152.     menubar->items = items;
  153.     menubar->selected = 0;
  154.     widget_want_cursor (menubar->widget, 0);
  155.     
  156.     return menubar;
  157. }
  158.